package com.heihei.service.impl;

import com.heihei.domain.User;
import com.heihei.domain.UserExample;
import com.heihei.mapper.UserMapper;
import com.heihei.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    //登录功能
    @Override
    public User login(String username, String password) {
        UserExample example = new UserExample();
        //添加用户名密码的条件查询
        example.createCriteria().andUsernameEqualTo(username).andPasswordEqualTo(password);

        List<User> users = userMapper.selectByExample(example);

        //登录成功
        if(users.size() == 1) {
            return users.get(0);
        }

        return null;
    }



}
